package com.situ.lession1226.controller;



import com.situ.lession1226.model.News;
import com.situ.lession1226.service.NewsService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Map;


//电影管理页面的的增删改查页面

@Controller
@RequestMapping("/news")
public class NewsController {
    private NewsService newsService;

    public NewsController(NewsService newsService) {
        this.newsService = newsService;
    }

    /**
     *
     *
     * @return
     */
    //@RequestMapping(value = "/list", method = {RequestMethod.GET, RequestMethod.POST, RequestMethod.DELETE})
    @GetMapping("/list")
    public String list(Map<String, Object> map) {
        //List<News> list = newsService.findAll();

        //map.put("newss", list);

        return "news/list";
    }

    /**
     * 处理/news/add请求
     *
     * @return
     */
    @GetMapping( "/add")
    public String add(){

        return "news/add";
    }
    /**
     * 进入修改页面
     *
     * @param map
     * @return
     */
    @GetMapping("/edit")
    public String edit(Integer id, Map<String, Object> map) {
        News news = newsService.findById(id);
        if (news == null) {
            map.put("error", "要修改的电影不存在");
        } else {
            map.put("stu", news);
        }
        return "news/edit";
    }
}
